﻿<Window x:Class="ttg_internal.Utilities.ParameterManager.View.MainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:convert="clr-namespace:ttg_internal.Utilities.Common.Converters;assembly=Utilities.Common"
    xmlns:viewModel="clr-namespace:ttg_internal.Utilities.ParameterManager.ViewModel"
    xmlns:utils="clr-namespace:ttg_internal.utils;assembly=UtilManager"
    Height="480" Width="640" Title="Parameter manager">
    
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Utilities.Common;component/Styles/DefaultStyles.xaml" />
                <ResourceDictionary Source="/Utilities.Common;component/Styles/CustomStyles.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    
    <TreeView ItemsSource="{Binding ParameterRoot}">
        <TreeView.ItemContainerStyle>
            <Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource {x:Type TreeViewItem}}">
                <Setter Property="IsExpanded" Value="True" />
            </Style>
        </TreeView.ItemContainerStyle>
        <TreeView.Resources>
            <convert:NotConverter x:Key="NotConverter" />
            
            <HierarchicalDataTemplate DataType="{x:Type viewModel:CompositeParameterSet}" ItemsSource="{Binding CompositeParameters}">
                <HierarchicalDataTemplate.ItemContainerStyle>
                    <Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource {x:Type TreeViewItem}}">
                        <Setter Property="IsExpanded" Value="False" />
                    </Style>
                </HierarchicalDataTemplate.ItemContainerStyle>
                <TextBlock Margin="3" Text="{Binding Name}" />
            </HierarchicalDataTemplate>
            <DataTemplate DataType="{x:Type utils:Parameter}">
                <StackPanel Margin="3">
                    <Label Content="{Binding Name}" />
                    <TextBox IsReadOnly="{Binding ReadOnly}" Text="{Binding Value}" Margin="0,3,0,0" />
                </StackPanel>
            </DataTemplate>
            <DataTemplate DataType="{x:Type utils:ParameterBool}">
                <CheckBox Content="{Binding Name}" IsChecked="{Binding BoolValue}" IsEnabled="{Binding ReadOnly, Converter={StaticResource NotConverter}}" Margin="3" />
            </DataTemplate>
            <DataTemplate DataType="{x:Type utils:ParameterDouble}">
                <StackPanel Margin="3">
                    <Label Content="{Binding Name}" />
                    <ContentControl Content="{Binding}">
                        <ContentControl.Style>
                            <Style TargetType="{x:Type ContentControl}">
                                <Setter Property="ContentTemplate">
                                    <Setter.Value>
                                        <DataTemplate>
                                            <TextBox IsReadOnly="{Binding ReadOnly}" Margin="0,3,0,0" Text="{Binding DoubleValue, ValidatesOnExceptions=True}" />
                                        </DataTemplate>
                                    </Setter.Value>
                                </Setter>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Info.HasBounds}" Value="True">
                                        <Setter Property="ContentTemplate">
                                            <Setter.Value>
                                                <DataTemplate>
                                                    <StackPanel>
                                                        <TextBlock Text="{Binding DoubleValue, StringFormat=\{0:F2\}}" HorizontalAlignment="Center" />
                                                        <Slider IsEnabled="{Binding ReadOnly, Converter={StaticResource NotConverter}}"
                                                                IsSnapToTickEnabled="False"
                                                                TickFrequency="0.01"
                                                                Minimum="{Binding Info.LowBound}" Maximum="{Binding Info.HighBound}" Value="{Binding DoubleValue}" />
                                                    </StackPanel>
                                                </DataTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </ContentControl.Style>
                    </ContentControl>
                </StackPanel>
            </DataTemplate>
            <DataTemplate DataType="{x:Type utils:ParameterEnum}">
                <StackPanel Margin="3">
                    <Label Content="{Binding Name}" />
                    <ComboBox IsReadOnly="{Binding ReadOnly}" ItemsSource="{Binding Info.Elements}" SelectedIndex="{Binding Index}" Margin="0,3,0,0" />
                </StackPanel>
            </DataTemplate>
            <DataTemplate DataType="{x:Type utils:ParameterInt64}">
                <StackPanel Margin="3">
                    <Label Content="{Binding Name}" />
                    <ContentControl Content="{Binding}">
                        <ContentControl.Style>
                            <Style TargetType="{x:Type ContentControl}">
                                <Setter Property="ContentTemplate">
                                    <Setter.Value>
                                        <DataTemplate>
                                            <TextBox IsReadOnly="{Binding ReadOnly}" Margin="0,3,0,0" Text="{Binding Int64Value, ValidatesOnExceptions=True}" />
                                        </DataTemplate>
                                    </Setter.Value>
                                </Setter>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Info.HasBounds}" Value="True">
                                        <Setter Property="ContentTemplate">
                                            <Setter.Value>
                                                <DataTemplate>
                                                    <StackPanel>
                                                        <TextBlock Text="{Binding Int64Value}" HorizontalAlignment="Center" />
                                                        <Slider IsEnabled="{Binding ReadOnly, Converter={StaticResource NotConverter}}"
                                                                Minimum="{Binding Info.LowBound}" Maximum="{Binding Info.HighBound}" Value="{Binding Int64Value}" />
                                                    </StackPanel>
                                                </DataTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </ContentControl.Style>
                    </ContentControl>
                </StackPanel>
            </DataTemplate>
        </TreeView.Resources>
    </TreeView>
</Window>